package commonFactors;

public class Solution {
    public int commonFactors(int a, int b) {
        int res=0;
        int c=gcd(a,b);
        for (int i = 1; i*i <=c ; i++) {
            if(c%i==0){
                res++;
                if(i*i!=c){
                    res++;
                }
            }
        }
        return res;
    }

    // 辗转相除法求最大公约数
    private int gcd(int a,int b){
        while(b!=0){
            int mod=a%b;
            a=b;
            b=mod;
        }
        return a;
    }
}
